package com.atguign.gulimall.order.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
@Slf4j
@Configuration
public class MqConfig {
    public static final String ORDER_DELAY_QUEUE = "order.delay.order.queue";
    public static final String ORDER_RELEASE_QUEUE = "order.release.order.queue";
    public static final String ORDER_EVENT_EXCHANGE = "order-event-exchange";
    public static final String ORDER_SECKILL_QUEUE = "order.seckill.order.queue";

    @Bean
    public Exchange orderEventExchange(){
        return new TopicExchange(ORDER_EVENT_EXCHANGE,true,false);
    }
    @Bean
    public Queue orderDelayQueue(){
        HashMap<String, Object> stringObjectHashMap = new HashMap<>();
        stringObjectHashMap.put("x-dead-letter-exchange",ORDER_EVENT_EXCHANGE);
        stringObjectHashMap.put("x-dead-letter-routing-key","order.release.order");
        stringObjectHashMap.put("x-message-ttl",60000*9);
        return new Queue(ORDER_DELAY_QUEUE,true,false,false,stringObjectHashMap);
    }
    @Bean
    public Queue orderReleaseQueue(){
        return new Queue(ORDER_RELEASE_QUEUE,true,false,false);
    }
    @Bean
    public Queue orderSeckillOrderQueue(){
        return new Queue(ORDER_SECKILL_QUEUE,true,false,false);
    }


    @Bean
    public Binding orderCreateBinding(){
        return new Binding(ORDER_DELAY_QUEUE, Binding.DestinationType.QUEUE,ORDER_EVENT_EXCHANGE,"order.create.order",null);
    }
    @Bean
    public Binding orderReleaseBinding(){
        return new Binding(ORDER_RELEASE_QUEUE, Binding.DestinationType.QUEUE,ORDER_EVENT_EXCHANGE,"order.release.order",null);
    }

    @Bean
    public Binding orderReleaseOtherBinding(){
        return new Binding("stock.release.stock.queue", Binding.DestinationType.QUEUE,ORDER_EVENT_EXCHANGE,"order.release.other.#",null);
    }
    @Bean
    public Binding orderSeckillOrderBinding(){
        return new Binding(ORDER_SECKILL_QUEUE, Binding.DestinationType.QUEUE,ORDER_EVENT_EXCHANGE,"order.seckill.other",null);
    }

}
